local skel = fk.CreateSkill{
  name = "kpaII__shengenhengmu",
}
local KleeU = require "packages/klee_xy_I/utility/k_utility"
Fk:loadTranslationTable{
  ["kpaII__shengenhengmu"] = "圣恩恒沐",
  [":kpaII__shengenhengmu"] = "回合内有角色受到伤害时，你可横置其以防止之，然后获得其一张牌。",
  ["#kpaII__shengenhengmu"] = "圣恩恒沐：你可横置 %src 以防止其受到的伤害",

  ["$kpaII__shengenhengmu1"] = "没人会死，我对天发誓。",
  ["$kpaII__shengenhengmu2"] = "王不弑王。",
}

skel:addEffect(fk.DetermineDamageInflicted,{
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and not target.chained and (player.room.current == player)
  end,
  on_cost = function (self, event, target, player, data)
    local yn = KleeU.askYesOrNo(player, "#kpaII__shengenhengmu:"..target.id ,skel.name)
    return yn
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    --横置并防止伤害
    target:setChainState(true)
    data:preventDamage()
    --获得牌，但是如果是自己，就只能获得装备区的
    if (target == player and #player:getCardIds("e") == 0) or (target ~= player and target:isNude()) then
      return
    end
    local card = room:askToChooseCard(player, {
      target = target,
      flag = target == player and "e" or "he",
      skill_name = skel.name,
    })
    room:obtainCard(player, card, false, fk.ReasonPrey, player, skel.name)
  end,
})

return skel